package com.yixin.hospital.controller;

import com.yixin.hospital.common.ApiResult;
import com.yixin.hospital.common.Constant;
import com.yixin.hospital.entity.dto.req.visitInspection.AddVisitInspectionReqDTO;
import com.yixin.hospital.service.VisitInspectionListService;
import com.yixin.hospital.utils.JwtUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

@RestController
@RequestMapping("/visit-inspection")
@Api(value = "检查管理", tags = "检查管理")
public class VisitInspectionController {
    @Resource
    private VisitInspectionListService visitInspectionListService;


    @PostMapping("/add-visit-inspection")
    @ApiOperation(value = "新增检查")
    @Transactional(rollbackFor = Exception.class)
    public ApiResult<?> addVisitInspection(@Valid @RequestBody AddVisitInspectionReqDTO addVisitInspectionReqDTO, HttpServletRequest request) {
        String userName = JwtUtil.getName(request.getHeader(Constant.AUTHORIZATION));
        return visitInspectionListService.addVisitInspection(addVisitInspectionReqDTO, userName);
    }

    @GetMapping("/get-visit-inspection-detail")
    @ApiOperation(value = "获取检查详情")
    public ApiResult<?> getVisitInspectionDetail(@RequestParam String guidanceCode) {
        return visitInspectionListService.getVisitInspectionDetail(guidanceCode);
    }

    @PostMapping("/take-visit-inspection")
    @ApiOperation(value = "完成实验室检查")
    @Transactional(rollbackFor = Exception.class)
    public ApiResult<?> takeVisitInspection(@Valid @RequestBody AddVisitInspectionReqDTO addVisitInspectionReqDTO, HttpServletRequest request) {
        String userName = JwtUtil.getName(request.getHeader(Constant.AUTHORIZATION));
        return visitInspectionListService.takeVisitInspection(addVisitInspectionReqDTO, userName);
    }
}
